package com.token.sysorg.webservice;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.token.sql.IntegrateSql;
import com.token.sysorg.enumerate.ActionTypeEnum;
import com.token.sysorg.impl.AbstractOrgHandlerImpl;
import com.token.sysorg.impl.LoadOrgCompanyInfoImpl;
import com.token.webservice.WebServiceMainImpl;

public class OrgWebServiceMain extends WebServiceMainImpl {

    private ActionTypeEnum actionType;
    private AbstractOrgHandlerImpl handler;

    public void setInDataStr(String jsonString) throws Exception {
        try {
            inData = JSON.parseObject(jsonString);
        } catch (JSONException e) {
            e.printStackTrace();
            throw new Exception("传入的Json字符串异常：" + jsonString);
        }

    }

    public void start(IntegrateSql iSql) throws Exception {
        String str = "";
    }

    public JSONObject getResult() {
        return null;
    }

    /**
     *
     * @return
     * @throws Exception
     */
    private AbstractOrgHandlerImpl getLoadOrgCompanyInfoImpl() throws Exception {
        LoadOrgCompanyInfoImpl impl = new LoadOrgCompanyInfoImpl();
        publicParam(impl);
        if (this.keyUnid == null || "".equals(keyUnid)) {
            impl.setLoadType(LoadFlowStepImpl.TYPE_FIRST);
            impl.setAppKeyId(needValue(inData.getString("appKeyId"), "应用KEYId", "appKeyId"));
            impl.setApplyer(needValue(inData.getString("applyer"), "申请人", "applyer"));
        } else {
            impl.setLoadType(LoadFlowStepImpl.TYPE_APPROVAL);
            impl.setKeyUnid(keyUnid);
        }
        return impl;
    }

    /**
     * @return AbstractFlowHandlerImpl
     */
    private AbstractOrgHandlerImpl getFlowHandlerByType() throws Exception {
        //根据提交类型来获取对应的处理类
        if (this.actionType == null) {
            throw new Exception("接口的操作类型[actionType]必须传入！");
        }

        //获取类型
        switch (actionType) {
            case LOADCOMINFO:
                return getLoadOrgCompanyInfoImpl();

            default:
                throw new Exception("actionType 接口类型不明确！");
        }
    }
}
